/*
 * Created on 2004-10-24
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package net.hnedu.search.dictionary;

import java.io.File;
import java.io.FilenameFilter;
import java.util.HashMap;
import java.util.Map;

import net.hnedu.config.ResConfig;
//import com.xerdoc.desktop.xdmf.XdmfPlugin;

/**
 * @author Winters.J.Mi
 *
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class DictionaryFactory {
	private static Map dictionaries_ = null;

	public static AbstractDictionary getDictionary(String name) {
		return (AbstractDictionary) dictionaries_.get(name);
	}

	protected static void loadSupportDictionary() {
		dictionaries_ = new HashMap();

		String dictionaryPath = ResConfig.DIC_IDR;
		File dicDir = new File(dictionaryPath);
		if (dicDir.isDirectory()) {
			File[] children = dicDir.listFiles(new FilenameFilter() {
				public boolean accept(File dir, String name) {
					return dir.isDirectory();
				}
			});

			if (children != null) {
				int length = children.length;
				for (int i = 0; i < length; i++) {
					File each = children[i];

					String name = each.getName();
					AbstractDictionary dic = new SimpleDictionary(name, each
							.getAbsolutePath());
					dictionaries_.put(name, dic);
					dic.loadDictionary();
				}
			}
		}
	}

	static {
		loadSupportDictionary();
	}
}
